﻿using System;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Framework.Core;
using Yoozoo.Managers;
using Yoozoo.Managers.ResourceManagerV2.Runtime;

namespace Gameplay.PVE.Survivor
{
    public class BattleFactory: BattleSingleton<BattleFactory>
    {
        public Bullet CreateBullet(BulletConfig config)
        {
            var bullet = ClassManager.Get<Bullet>();
            BulletMovement movement = null;
            //组装移动类型
            if (config.move_type == (int)EBulletMovementType.Track)
            {
                movement = ClassManager.Get<TrackMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.Straight)
            {
                movement = ClassManager.Get<StraightMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.Parabola)
            {
                movement = ClassManager.Get<ParabolaMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.SpecialParabola)
            {
                movement = ClassManager.Get<SpecialParabolaMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.Trap)
            {
                movement = ClassManager.Get<TrapMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.Stick)
            {
                movement = ClassManager.Get<StickMovement>();
            }
            else if (config.move_type == (int)EBulletMovementType.WaveShoot)
            {
                movement = ClassManager.Get<WaveShootMovement>();
            }
            else
            {
                UnityEngine.Debug.LogError(config.id + " 未实现的子弹类型" + config.move_type);
            }
            /*else if (config.movementType == EBulletMovementType.Straight)
            {
                bullet.movement = new StraightMovement();
            }*/
            bullet.SetMovement(movement);
            return bullet;
        }

        public void DestroyBullet(Bullet bullet)
        {
            ClassManager.Free(bullet);
        }

        public ElementBase CreateElement(ElementConfig config)
        {
            ElementBase element = null;
            if (config.main_type == (int)EBattleElementMainType.Damage)
            {
                element =ClassManager.Get<DamageElement>();
            }
            else if (config.main_type == (int)EBattleElementMainType.ChangeProperty)
            {
                element = ClassManager.Get<ChangePropertyElement>();
            }
            else if (config.main_type == (int)EBattleElementMainType.Trigger)
            {
                element = ClassManager.Get<TriggerElement>();
            }
            else if (config.main_type == (int)EBattleElementMainType.Control)
            {
                element = ClassManager.Get<ControlElement>();
            }
            else if (config.main_type == (int)EBattleElementMainType.Immune)
            {
                element = ClassManager.Get<ImmunityElement>();
            }
            else if (config.main_type == (int)EBattleElementMainType.Shield)
            {
                element = ClassManager.Get<ShieldElement>();
            }
            else
            {
                UnityEngine.Debug.LogError("未实现的元素类型" + config.main_type);
            }
            return element;
        }

        public BattleUnit CreateBattleUnit()
        {
            return ClassManager.Get<BattleUnit>();
        }
        
        public EnvironmentUnit CreateEnvironmentUnit()
        {
            return ClassManager.Get<EnvironmentUnit>();
        }

        public NpcUnit CreateNpcUnit()
        {
            return ClassManager.Get<NpcUnit>();
        }
        
        public NpcUnit CreateTruckUnit()
        {
            return ClassManager.Get<TruckUnit>();
        }
    }
}
